/*
 * File Name: Launcher.java
 * Created on: 
 */
package co.edu.uniandes.intercon.client;

import java.awt.EventQueue;

import co.edu.uniandes.intercon.client.gui.common.window.EAppExecutionMode;
import co.edu.uniandes.intercon.client.gui.common.window.MainWindow;
import co.edu.uniandes.intercon.client.gui.util.WindowHelper;
import co.edu.uniandes.intercon.server.util.PropertiesHelper;

/**
 * Startup class used to initiate the application
 * 
 * @see EAppExecutionMode
 * @author Fabian Gutierrez [fagossa@gmail.com]
 */
public class Launcher {

    /*
     * Error shown when there is an error persisting the config file
     */
    public static final String ERROR_PERSISTING_PROPERTIES =
            "Error persisting properties into config file";
    /*
     * Error shown when there is an error with the config starting up the 
     * client
     */
    public static final String ERROR_CLIENT_CONFIG =
            "server unreachable. Do yout wish to continue?";
    /*
     * Error shown when the is an error starting up the server
     */
    public static final String ERROR_SERVER_CONFIG =
            "The port specified is not valid.\n Do yout wish to continue?";
    /*
     * Error shown when there is an error in the client communication 
     * configuration
     */
    public static final String ERROR_COMM_CONFIG =
            "There is an error with your communication config. \n" +
            "Do you wish to continue?";
    
    /*
     * Default width used when the property 
     * {@link PropertiesHelper.WIDTH_PROPERTY} could not be found
     */
    private static final int DEFAULT_WIDTH = 600;
    /*
     * Default height used when the property 
     * {@link PropertiesHelper.HEIGHT_PROPERTY}
     * could not be found
     */
    private static final int DEFAULT_HEIGHT = 700;

    /**
     * Startups the application
     * @param args contains the operation mode of the application. The available
     * modes are <code>server</code> or <code>alone</code>.
     */
    public static void main(String[] args) throws Exception {
    	startMainWindow();
    }
    
    /*
     * Starts main window in a lazy way
     */
    private static void startMainWindow() {
        Runnable runner = new Runnable() {
            public void run() {
                    MainWindow gui = new MainWindow(PropertiesHelper.stringProperty(
                            PropertiesHelper.TITLE_PROPERTY,
                            "P2P Software"));
                    int width = PropertiesHelper.intProperty(
                            PropertiesHelper.WIDTH_PROPERTY, DEFAULT_WIDTH);
                    int height = PropertiesHelper.intProperty(
                            PropertiesHelper.HEIGHT_PROPERTY, DEFAULT_HEIGHT);
                    gui.setSize(width, height);
                    WindowHelper.centerWindow(gui);
                    gui.setVisible(true);
            }
        };
        EventQueue.invokeLater(runner);
    }
}
